package com.reisen;

import com.reisen.utils.PathUtils;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.web.reactive.config.ResourceHandlerRegistry;
import org.springframework.web.reactive.config.WebFluxConfigurer;

/**
 * @author reisen7
 * @date 2025/6/1 2:47
 * @description 网关
 */

@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
@EnableDiscoveryClient
public class GatewayApplication implements WebFluxConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 歌手头像地址：映射到项目根目录下的 img/singerPic 目录
        registry.addResourceHandler("/img/singerPic/**").addResourceLocations(
                "file:///" + System.getProperty("user.dir") + "/img/singerPic/");
        // 歌单图片地址：映射到项目根目录下的 img/songListPic 目录
        registry.addResourceHandler("/img/songListPic/**").addResourceLocations(
                "file:///" + System.getProperty("user.dir") + "/img/songListPic/");
        // 歌曲图片地址：映射到项目根目录下的 img/songPic 目录
        registry.addResourceHandler("/img/songPic/**").addResourceLocations(
                "file:///" + System.getProperty("user.dir") + "/img/songPic/");
        // 歌曲地址：映射到项目根目录下的 song 目录
        registry.addResourceHandler("/songFile/**").addResourceLocations(
                "file:///" + System.getProperty("user.dir") + "/songFile/");
        // 前端用户头像地址：映射到项目根目录下的 userImages 目录
        registry.addResourceHandler("/userImages/**").addResourceLocations(
                "file:///" + System.getProperty("user.dir") + "/userImages/");
        // 用户头像默认地址：映射到项目根目录下的 img 目录（覆盖通用路径）
        registry.addResourceHandler("/img/**").addResourceLocations(
                "file:///" + System.getProperty("user.dir") + "/img/");
    }

    public static void main(String[] args) {
        SpringApplication.run(GatewayApplication.class, args);
    }
}